package cn.wolfcode.wolf2w.business.controller;


import cn.wolfcode.wolf2w.business.api.domain.Answer;
import cn.wolfcode.wolf2w.business.api.domain.Question;
import cn.wolfcode.wolf2w.business.query.QuestionQuery;
import cn.wolfcode.wolf2w.business.service.IAnswerService;
import cn.wolfcode.wolf2w.business.service.IQuestionService;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 问答 Controller
 * 
 * @author zhuyaohua
 * @date 2024-10-01
 */
@RestController
//@RequestMapping("questions")
@RequestMapping("destinationDoubt")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;
    @Autowired
    private IAnswerService answerService;
//    /**
//     * 问答详情
//     */
//    @GetMapping("/detail/{id}")
//    public R<Question> detail(@PathVariable Long id) {
//        Question question = questionService.getById(id);
//        return R.ok(question);
//    }
//    /**
//     * 问答 列表
//     */
//    @GetMapping("/query")
//    public R<IPage<Question>> query(QuestionQuery qo) {
//        IPage<Question> page = questionService.queryPage(qo);
//        return R.ok(page);
//    }
// http://localhost:3000/api/qa/destinationDoubt/page?current=1&size=10
    @GetMapping("/page")
    public R<IPage<Question>> query(int current, int size) {
        QuestionQuery qo = new QuestionQuery();
        qo.setCurrentPage(current);
        qo.setPageSize(size);
        IPage<Question> page = questionService.queryPage(qo);
        return R.ok(page);
    }



    //http://localhost:3000/api/qa/destinationDoubt/detail/1
    @GetMapping("/detail/{id}")
    public R<Question> detail(@PathVariable("id") Long id) {
        Question question = questionService.selectById(id);
        return R.ok(question);
    }

    @PostMapping("/create")
    public R<Question> create(@RequestBody Question question) {
        boolean save = questionService.insert(question);
        return R.ok();
    }

    @GetMapping("/self/question")
    public R<IPage<Question>> selfQuestion(int current, int size) {
        QuestionQuery qo = new QuestionQuery();
        qo.setCurrentPage(current);
        qo.setPageSize(size);
        IPage<Question> page = questionService.queryPageSelf(qo);
        return R.ok(page);
    }

    @PostMapping("/answer")
    public R<Question> answer(@RequestBody Answer answer) {
        boolean save = answerService.insert(answer);
        return R.ok();
    }
    @PostMapping("/focus/{destinationId}")
    public R<?> focus(@PathVariable("destinationId") Long destinationId){
        //Map<String,Object> map = answerService.getMap()
        return R.ok(new HashMap<>());
    }
    @PostMapping("/unfocus/{destinationId}")
    public R<?> unfocus(@PathVariable("destinationId") Long destinationId){

        return R.ok(new HashMap<>());
    }


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Question>> feignList() {
        return R.ok(questionService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Question> feignGet(@PathVariable Long id) {
        return R.ok(questionService.selectById(id));
    }

}
